package mini.hug;

import java.awt.geom.Ellipse2D;

import owg.util.Calc;
import owg.util.opengl.ColorF;
import world.Sound;
import hubol.Entity;

public class Borgus extends Entity{
	private final Shake s = Hug.me.shake(), t = Hug.me.shake(), u = Hug.me.shake();
	public final Ellipse2D speakMask, hugMask;
	private float in = 0;
	
	public int message;
	public boolean speak = false, prev = false;
	public boolean hug = false, fuk = false;

	public Borgus(double x, double y, int message) {
		super(x, y, 4);
		this.message = message;
		sprite = Hug.BORGUS;
		alarmEvent(0);
		
		speakMask = centerize(new Ellipse2D.Double(x, y, 360 * (Hug.SIZE / .35), 200 * (Hug.SIZE / .35)));
		hugMask = centerize(new Ellipse2D.Double(x, y, 165 * (Hug.SIZE / .35), 55 * (Hug.SIZE / .35)));
		
		setDepth(600 - (int)y);
	}
	
	public Ellipse2D centerize(Ellipse2D old){
		return new Ellipse2D.Double(old.getX() - (old.getWidth() / 2.0), old.getCenterY() - (old.getHeight()), old.getWidth(), old.getHeight());
	}
	
	public void hug(){
		Hug.me.bogus.step.stop();
		Hug.me.bogus.hspeed = 0;
		Hug.me.bogus.vspeed = 0;
		
		if (message < 3){
			Bogus b = Hug.me.bogus;
			b.x = x - 47;
			b.y = y;
			b.ACTUALLYHUGGING = true;
			hug = true;
			Sound.playPitched("hug");
			alarm[1] = 60;
		}
		else{
			//TODO kill
			Sound.playPitched("youarebad", .254);
			Hug.me.pitch(.1);
			Hug.me.bogus.DEAD = true;
			fuk = true;
			alarm[2] = 90;
		}
	}
	
	public void alarmEvent(int i){
		if (i == 0){
			imageSingle = (float)Calc.random(2);
			imageSpeed = (float)Calc.rangedRandom(.125);
			alarm[0] = 1 + (int)Calc.random(60);
		}
		else if (i == 1){
			Bogus b = Hug.me.bogus;
			b.heart();
			b.ACTUALLYHUGGING = false;
			Hug.me.borgus.remove(this);
			new Birgus(x + 12, y - 82);
			destroy();
		}
		else if (i == 2){
			new Lightning();
		}
	}
	
	public void step(){
		speak = false;
		in = (float)Calc.approach(in, 1, 4);
		imageSingle += imageSpeed;
		alarmStep();
	}
	
	public void render(){
		prev = speak;
		if (!hug){
			int img = 0;
			if (speak)
				img = 1;
			sprite.render(img, x + s.x, y + s.y, xscale * Hug.SIZE * in, Hug.SIZE * in, (float)(s.z / 10.0), ColorF.WHITE);
			if (speak){
				Hug.SPEECH.render(Math.abs((imageSingle + 3) * 1.05) % 2.0, x + t.x, y + t.y - (242 * (Hug.SIZE / .35)), xscale * Hug.SIZE * in, Hug.SIZE * in, (float)(t.z / 18.0), ColorF.WHITE);
				Hug.TEXT.render(message, x + u.x, y + u.y - (266 * (Hug.SIZE / .35)), xscale * Hug.SIZE * in, Hug.SIZE * in, (float)(u.z / 8.0), ColorF.WHITE);
			}
		}
	}

}
